package com.eastone.user.serverapi.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.yjx.framework.cache.CacheSimpleManger;
import com.yjx.framework.util.SpringUtil;

public class WebListenter implements ServletContextListener {
	private static final Logger LOG = LogManager.getLogger(WebListenter.class);

	private static ServletContext servletContext;

	private void cacheLoad() {
		CacheSimpleManger.cacheLoad();
	}

	public void contextInitialized(ServletContextEvent event) {
		if (LOG.isDebugEnabled()) {
			LOG.debug("WebListenter contextInitialized(ServletContextEvent event) start");
		}
		servletContext = event.getServletContext();
		SpringUtil.setApplicationContext(WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext));

		// MessageSourceUtil.setMessageSource((MessageSource)
		// SpringUtil.getBean("messageSource"));

		cacheLoad();

		// RedisConnectionPool redisConnPool =
		// RedisConnectionPool.getInstance();
		// redisConnPool.getSessionConnection();

		if (LOG.isDebugEnabled()) {
			LOG.debug("WebListenter contextInitialized(ServletContextEvent event) end");
		}
	}

	public void contextDestroyed(ServletContextEvent event) {
	}

	public static ServletContext getServletContext() {
		return servletContext;
	}

}
